import router from '@/router'
import {post} from '@/util/request'

export default {
	namespace:'driverView',
	namespaced:true,
	state:{
		isLoading:false,
		isModalLoading:false,
    pageData:{}
	},
	mutations:{
		changeLoading(state,v){
			state.isLoading = v;
		},
		changeModalLoading(state,v){
			state.isModalLoading = v;
		},
    changePagedata(state,v){
      state.pageData = v;
    }
	},
	actions:{
    async reload({commit},query){
      commit('changeLoading',true);
      let res = await post('/driver/driverView/list',query);
      commit('changePagedata',res.data.data);
      commit('changeLoading',false);
    },
    loadDetail({commit},query){
      commit('changeLoading',true);
      return post('/driver/driverView/findDriverViewDetail',query).then(res => {
        commit('changeLoading',false);
        return res.data;
      });
    },
		loadMood({commit},query){
			return post('/driver/driverView/findDriverEmotion',query).then(res => {
				return res.data;
			});
		},
		loadHabits({commit},query){
			return post('/driver/driverView/findDriverHabits',query).then(res => {
				return res.data;
			});
		}
	},
	subscriptions({dispatch},router){
		//给路由加监听一旦进入module绑定的页面时dispatch初始化action
		router.afterEach((to,from)=>{
			if(to.name === this.namespace){

			}
		})
	}
}
